package com.gykfbxxh.imovie.listener;

import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;

import com.app.utils.util.ViewSizeUtils;
import com.gykfbxxh.imovie.base.BaseActivity;


/**
 * 返回手势监听接口
 */
public class BackGestureListener implements OnGestureListener {
	BaseActivity activity;
	boolean isDown;
	int longX;//屏幕宽度
	
	public BackGestureListener(BaseActivity activity) {
		this.activity = activity; 
	}

	@Override
	public boolean onDown(MotionEvent e) {
		// TODO Auto-generated method stub
		isDown=true;
		return false;
	}

	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
			float velocityY) {
		isDown=false;
		return false;
	}

	@Override
	public void onLongPress(MotionEvent e) {
		isDown=false;
	}

	@Override
	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
			float distanceY) {

		if (isDown) {
			if (longX == 0) {
				longX = ViewSizeUtils.getWidthPixels() / 5;
			}
			if ((e2.getX() - e1.getX()) > longX && Math.abs(e1.getY() - e2.getY()) < 60) {
				activity.onBackPressed();
				isDown = false;
				return true;
			}
		}

		return false;


	}

	@Override
	public void onShowPress(MotionEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean onSingleTapUp(MotionEvent e) {
		// TODO Auto-generated method stub
		return false;
	}

}
